﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Home.Utils;
using NhanAi.DAO;
using NhanAi.DAO.Mix;
using NhanAi.Entity;
using NhanAi.App_Code;

namespace NhanAi.Admin
{
    public partial class ListComments : ListPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Authenticate();
            CommentDao daoCom = new CommentDao();
            string searchString = Request["searchString"];
            bool approved=Request["approved"]=="yes";
            pageNum = TypeWrapper.GetInt32(Request["page"]);
            if (pageNum == 0) pageNum = 1;
            int total = 0;
            if (Request.HttpMethod == "POST")
            {
                string ids = Request["ids"];
                if (!String.IsNullOrEmpty(ids))
                {
                    try
                    {
                        daoCom.Delete(ids);
                        SetMessage("Xóa thành công", "");
                    }
                    catch (Exception ex)
                    {
                        SetMessage("Đã xảy ra lỗi", "");
                      
                    }
                }
            }
            List<Comment> list;
            total = 0;
            if (!String.IsNullOrEmpty(searchString))
            {
                list = daoCom.ReadMany(PAGE_SIZE, pageNum, -1, "%" + searchString + "%", "%" + searchString + "%",approved,null,null,out total);
            }
            else
            {
                list = daoCom.ReadMany(PAGE_SIZE, pageNum, -1,null, null, approved, null, null, out total);
            }
            rptData.DataSource = list;
           
            rptData.DataBind();
            paging.TotalItemCount = total;
            paging.PageNumber = pageNum;
            paging.PageSize = PAGE_SIZE;
            paging.SearchString = searchString;
            SetCurrentPage("Comment");
        }
    }
}